//
//  PlanViewCell.m
//  XhlTrip
//
//  Created by dllo on 15/8/24.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "PlanViewCell.h"
#import "PlanModel.h"
#import "UIImageView+WebCache.h"

@implementation PlanViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.mage = [[UIImageView alloc] init];
        [self.contentView addSubview:self.mage];
        [_mage release];
        
        self.nameLabel = [[UILabel alloc] init];
        [self.mage addSubview:self.nameLabel];
        [_nameLabel release];
        
        self.daysLabel = [[UILabel alloc] init];
        [self.mage addSubview:self.daysLabel];
        [_daysLabel release];
        
        self.countLabel = [[UILabel alloc] init];
        [self.mage addSubview:self.countLabel];
        [_countLabel release];
        
        self.desLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.desLabel];
        [_desLabel release];
        _desLabel.numberOfLines = 0;
        
        _nameLabel.font = [UIFont fontWithName:@"Verdana-BoldItalic" size:19 * Width];
        _desLabel.font = [UIFont fontWithName:@"Verdana-Italic" size:15 * Width];
        _daysLabel.font = [UIFont fontWithName:@"Verdana-BoldItalic" size:15 * Width];
        _countLabel.font = [UIFont fontWithName:@"Verdana-BoldItalic" size:15 * Width];

       
        _desLabel.textColor = [UIColor blackColor];
        _nameLabel.textColor = [UIColor whiteColor];
        _daysLabel.textColor = [UIColor whiteColor];
        _countLabel.textColor = [UIColor whiteColor];
        


    }
    return self;
}
#pragma mark - 文字高度自适应
+ (CGFloat)heightWithText:(NSString *)text width:(CGFloat )width
{
    
    CGRect rect = [text boundingRectWithSize:CGSizeMake(width, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont fontWithName:@"Verdana-Italic" size:15 * Width]} context:nil];
    return rect.size.height;
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    self.mage.frame = CGRectMake(10 * Width, 10 * Height, self.contentView.frame.size.width - 20 * Width, 180 * Height);
    self.nameLabel.frame = CGRectMake(10 * Width, self.mage.frame.size.height - 60 * Height, self.mage.frame.size.width - 20 * Width, 30 * Height);
    self.daysLabel.frame = CGRectMake(10 * Width, self.mage.frame.size.height - 29 * Height, 40 * Width, 30 * Height);
    self.countLabel.frame = CGRectMake(45 * Width, self.mage.frame.size.height - 29 * Height, 100 * Width, 30 * Height);
    
    CGFloat y = self.contentView.frame.size.width - 20 * Width;
    CGFloat height = [[self class] heightWithText:self.desLabel.text width:y];
    self.desLabel.frame = CGRectMake(10 * Width, self.mage.frame.size.height + 15 * Height, self.contentView.frame.size.width - 20 * Width, height);
    
}


- (void)setPlanModel:(PlanModel *)planModel
{
    if (_planModel != planModel) {
        [_planModel release];
        _planModel = [planModel retain];
    }
    self.nameLabel.text = planModel.name;
    NSString *day = [NSString stringWithFormat:@"%@%@", [planModel.plan_days_count stringValue], @"天"];
    self.daysLabel.text = day;
    [self.mage sd_setImageWithURL:planModel.image_url];
    
    NSString *count = [NSString stringWithFormat:@"%@%@", [planModel.plan_nodes_count stringValue], @"旅行地"];
    self.countLabel.text = count;
}
- (void)dealloc
{
    [_planModel release];
    [_nameLabel release];
    [_daysLabel release];
    [_countLabel release];
    [_mage release];
    [_desLabel release];
    [super dealloc];
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
